var pageSize = 10;
var pageNum = 1;
var page;
var laypage;
var list;



$(function () {
    $("#menuId").val(sessionStorage.menuId);
    var menuId = $("#menuId").val();
    if(sessionStorage.getItem(menuId+'add') == 1){
        $("#addPopupAdvert").css('display','inline');
    }
    // alert("000"+sessionStorage.menuId);
    layui.use(['laydate','element','laypage','layer'], function(){
        $ = layui.jquery;//jquery
        laydate = layui.laydate;//日期插件
        element = layui.element();//面包导航
        laypage = layui.laypage;//分页
        layer = layui.layer;//弹出层

        //以上模块根据需要引入

        // var start = {
        //     // min: laydate.now(),
        //     max: '2099-06-16 23:59:59'
        //     ,istoday: true
        //     ,choose: function(datas){
        //         end.min = datas; //开始日选好后，重置结束日的最小日期
        //         end.start = datas //将结束日的初始值设定为开始日
        //     }
        // };
        //
        // var end = {
        //     // min: laydate.now(),
        //     max: '2099-06-16 23:59:59'
        //     ,istoday: false
        //     ,choose: function(datas){
        //         start.max = datas; //结束日选好后，重置开始日的最大日期
        //     }
        // };
        //
        // document.getElementById('LAY_demorange_s').onclick = function(){
        //     start.elem = this;
        //     laydate(start);
        // }
        // document.getElementById('LAY_demorange_e').onclick = function(){
        //     end.elem = this
        //     laydate(end);
        // }
    });
    setTimeout(function () {
        findNewUserAdvert();
    },200);

});



//查询新用户福袋
function findNewUserAdvert(){
    var menuId = $("#menuId").val();
    var startTime = $("#LAY_demorange_s").val();
    var endTime = $("#LAY_demorange_e").val();

    var params = {
        "type":"query",
        "menuId":menuId,
        "pageSize":pageSize,
        "pageNum":pageNum,
        "startTime":startTime,
        "endTime":endTime

    };
    $.ajax({
        type:"post",
        url: "/advert/findNewUserAdvert",
        data:params,
        dataType: "json",
        success : function(data){
            if(data.code = 1 && data.code != undefined){
                list = data.adverts;
                page = data.page;
                var html = "";
                for(var b in list){
                    var advertType = "";
                    if(list[b].advertType == -1){
                        advertType = "新用户福袋";
                    }
                    var isDelete = "";
                    if(list[b].isDelete == 0){
                        isDelete = "无效";
                    }else if(list[b].isDelete == 1){
                        isDelete = "有效";
                    }
                    html += '<tr><td>'+list[b].id+'</td>' +
                        '<td>'+advertType+'</td>' +
                        '<td><label onclick="findDetails('+b+')" style="color: #0b6cbc;cursor: pointer">查看</label></td>' +
                        '<td>'+list[b].redEnvelopeAmount+'</td>' +
                        '<td>'+(list[b].startTime == null ? "" : new Date(list[b].startTime).toLocaleString())+'</td>' +
                        '<td>'+(list[b].endTime == null ? "" : new Date(list[b].endTime).toLocaleString())+'</td>' +
                        '<td>'+(list[b].createTime == null ? "" : new Date(list[b].createTime).toLocaleString()) +'</td>' +
                        '<td>'+(list[b].modifyTime == null ? "" : new Date(list[b].modifyTime).toLocaleString()) +'</td><td>';
                    if(sessionStorage.getItem(menuId+'edit') == 1){
                        html += '<button onclick="showUpdatePage('+b+')" value="1" class="layui-btn layui-btn-normal">修改</button>';
                    }
                    if(sessionStorage.getItem(menuId+'del') == 1){
                        html += '<button onclick="showDelPage('+list[b].id+')" class="layui-btn layui-btn-danger">删除</button>';
                    }
                    html += '</td></tr>';
                }
                $("#bus").html(html);
                $("#total").html("共有数据："+page.total+" 条");
                laypage({
                    cont: 'page'
                    ,pages: page.pages
                    ,first: 1
                    ,curr:pageNum
                    ,last: page.pages
                    ,prev: '<em><</em>'
                    ,next: '<em>></em>'
                    ,jump: function (obj,first) {
                        pageNum = obj.curr;
                        if(!first){
                            findNewUserAdvert();
                        }
                    }
                });
            }else if(data == 9999 && data != undefined){
                window.location.href = "/login_toLogin";
            }else if(data == 1111 && data != undefined){
                alert("无权操作");
            }else if(data.code == 2 && data.code != undefined){
                alert(data.message);
            }
        }

    });
}

//查询按钮
function search() {
    pageNum = 1;
    findBannerList();
}
//打开删除询问页面
var delIndex;
function showDelPage(id) {
    var html = "<div style='text-align: center'><p style='margin-bottom: 30px'>确定删除吗?</p><button onclick='delBanner("+id+","+1+",this)' class='layui-btn layui-btn-normal'>确定</button><button onclick='delBanner("+id+","+2+",this)' class='layui-btn layui-btn-normal' style='background-color: #ff5722;margin-left: 100px'>取消</button></div>"
    delIndex = layer.open({
        title: ['提示','color: #2299ee;border-bottom: 1px solid;']
        ,type: 1
        ,content: html
        ,area: ['300px', '150px']
        ,maxmin:true
    });
}
//删除
function delBanner(id,index,obj) {
    $(obj).attr("disabled",true);
    if(index == 2){
        layer.close(delIndex);
        return false;
    }
    var menuId = $("#menuId").val();
    var params = {
        "type":"del",
        "menuId":menuId,
        "id":id
    };
    $.ajax({
        type:"post",
        url:"/advert/delNewUserAdvert",
        data:params,
        dataType:"json" ,
        success :function (data) {

            if(data.code == 1 && data.code != undefined){
                alert("删除成功");
                layer.close(delIndex);
                findNewUserAdvert();
            }else if(data == 9999 && data != undefined){
                window.location.href = "/login_toLogin";
            }else if(data == 1111 && data != undefined){
                alert("无权操作");
                $(obj).attr("disabled",false);
            }else if(data.code == 2 && data.code != undefined){
                alert("删除失败");
                $(obj).attr("disabled",false);
            }
        }
    });
}


//打开添加页面
var addIndex;
function showAddPage() {
    var html = '<table style="border-collapse: separate;border-spacing: 10px"><tr><td style="text-align: right">福袋内容</td><td><textarea id="advertContent" style="height: 50px;width: 472px"></textarea></td></tr>' +
        '<tr><td style="text-align: right">福袋金额(单位:分)</td><td><input id="redEnvelopeAmount" style="height: 30px;width: 472px"/></td></tr>'+
        '<tr style="height: 300px"><td style="text-align: right">福袋图片(至少上传一张)</td><td><div><div id="d1" onclick="im1.click()" style="width: 150px;height: 150px;border: 1px solid darkgrey;display: inline-block;vertical-align: top;text-align: center;line-height: 150px;cursor: pointer"><input onchange="preview(this,1)" id="im1" type="file" style="display: none"/><label id="t1">点击上传图片一</label><img id="img1" src="" style="width: 150px;height: 150px;display: none"/></div>'+
        '<div id="d2" onclick="im2.click()" style="width: 150px;height: 150px;border: 1px solid darkgrey;display: inline-block;vertical-align: top;margin-left: 10px;text-align: center;line-height: 150px;cursor: pointer"><input onchange="preview(this,2)" id="im2" type="file" style="display: none"/><label id="t2">点击上传图片二</label><img id="img2" src="" style="width: 150px;height: 150px;display: none"/></div>'+
        '<div id="d3" onclick="im3.click()" style="width: 150px;height: 150px;border: 1px solid darkgrey;display: inline-block;vertical-align: top;margin-left: 10px;text-align: center;line-height: 150px;cursor: pointer"><input onchange="preview(this,3)" id="im3" type="file" style="display: none"/><label id="t3">点击上传图片三</label><img id="img3" src="" style="width: 150px;height: 150px;display: none"/></div><br/><br/>'+
        '<div id="d4" onclick="im4.click()" style="width: 150px;height: 150px;border: 1px solid darkgrey;display: inline-block;vertical-align: top;text-align: center;line-height: 150px;cursor: pointer"><input onchange="preview(this,4)" id="im4" type="file" style="display: none"/><label id="t4">点击上传图片四</label><img id="img4" src="" style="width: 150px;height: 150px;display: none"/></div>'+
        '<div id="d5" onclick="im5.click()" style="width: 150px;height: 150px;border: 1px solid darkgrey;display: inline-block;vertical-align: top;margin-left: 10px;text-align: center;line-height: 150px;cursor: pointer"><input onchange="preview(this,5)" id="im5" type="file" style="display: none"/><label id="t5">点击上传图片五</label><img id="img5" src="" style="width: 150px;height: 150px;display: none"/></div>'+
        '<div id="d6" onclick="im6.click()" style="width: 150px;height: 150px;border: 1px solid darkgrey;display: inline-block;vertical-align: top;margin-left: 10px;text-align: center;line-height: 150px;cursor: pointer"><input onchange="preview(this,6)" id="im6" type="file" style="display: none"/><label id="t6">点击上传图片六</label><img id="img6" src="" style="width: 150px;height: 150px;display: none"/></div><br/><br/>'+
        '<div id="d7" onclick="im7.click()" style="width: 150px;height: 150px;border: 1px solid darkgrey;display: inline-block;vertical-align: top;text-align: center;line-height: 150px;cursor: pointer"><input onchange="preview(this,7)" id="im7" type="file" style="display: none"/><label id="t7">点击上传图片七</label><img id="img7" src="" style="width: 150px;height: 150px;display: none"/></div>'+
        '<div id="d8" onclick="im8.click()" style="width: 150px;height: 150px;border: 1px solid darkgrey;display: inline-block;vertical-align: top;margin-left: 10px;text-align: center;line-height: 150px;cursor: pointer"><input onchange="preview(this,8)" id="im8" type="file" style="display: none"/><label id="t8">点击上传图片八</label><img id="img8" src="" style="width: 150px;height: 150px;display: none"/></div>'+
        '<div id="d9" onclick="im9.click()" style="width: 150px;height: 150px;border: 1px solid darkgrey;display: inline-block;vertical-align: top;margin-left: 10px;text-align: center;line-height: 150px;cursor: pointer"><input onchange="preview(this,9)" id="im9" type="file" style="display: none"/><label id="t9">点击上传图片九</label><img id="img9" src="" style="width: 150px;height: 150px;display: none"/></div>'+
        '</div></td></tr></table>'+
        "<button onclick='addNewUserAdvert(this)' class='layui-btn layui-btn-normal' style='float: right;margin-right: 10px;margin-top: 57px;margin-bottom: 10px'>提交</button>";
    addIndex = layer.open({
        title: ['添加新用户福袋','color: #2299ee;border-bottom: 1px solid;']
        ,type: 1
        ,content: html
        ,area: ['60%', '80%']
        ,maxmin:true
    });
}
//图片预览
function preview(file, id) {
    var prevDiv = document.getElementById('d' + id);
    if(!file.files[0]){
        $("#img"+id).attr("src","");
        $("#img"+id).css("display","none");
        $("#t"+id).css("display","block");
        $(prevDiv).attr("line-height","30px");
        return;
    }

    var fileType = file.files[0].type;
    if(fileType != "image/pjpeg" && fileType != "image/jpeg" && fileType != "image/x-png" && fileType != "image/png"){
        alert("图片类型错误");
        return false;
    }
    if (file.files && file.files[0]) {
        var reader = new FileReader();
        reader.onload = function (evt) {
            $("#t"+id).css("display","none");
            $(prevDiv).removeAttr("line-height");
            $("#img"+id).attr("src",evt.target.result);
            $("#img"+id).css("display","block");
            // prevDiv.innerHTML = '<input onchange="preview(this,'+id+')" id="im'+id+'" type="file" style="display: none"/><img src="' + evt.target.result + '" style="width: 150px;height: 150px;"/>';
        }
        reader.readAsDataURL(file.files[0]);
    } else {
        prevDiv.innerHTML = '<input onchange="preview(this,'+id+')" id="im'+id+'" type="file" style="display: none"/><div class="img" style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale,src=\'' + file.value + '\'"></div>';
    }
}
//添加福袋
function addNewUserAdvert(obj) {
    $(obj).attr("disabled",true);
    $(obj).attr("class","layui-btn layui-btn-disabled");

    var menuId = $("#menuId").val();
    var formData = new FormData();

    var advertContent = $("#advertContent").val();
    if(advertContent == "" || advertContent == undefined){
        alert("福袋内容不能为空");
        $(obj).attr("disabled",false);
        $(obj).attr("class","layui-btn layui-btn-normal");
        return false;
    }
    var redEnvelopeAmount = $("#redEnvelopeAmount").val();
    if(redEnvelopeAmount == "" || redEnvelopeAmount == undefined){
        alert("福袋金额不能为空");
        $(obj).attr("disabled",false);
        $(obj).attr("class","layui-btn layui-btn-normal");
        return false;
    }
    if(isNaN(redEnvelopeAmount)){
        alert("福袋金额填写错误");
        $(obj).attr("disabled",false);
        $(obj).attr("class","layui-btn layui-btn-normal");
        return false;
    }
    var files = new Array();
    for(var i=1;i<=9;i++){
        var file = $("#im"+i)[0].files[0];
        if(file != undefined){
            files.push(file);
            formData.append("files",file);
        }
    }
    console.log(files.length);
    if(files.length <= 0){
        alert("请最少上传一张图片");
        $(obj).attr("disabled",false);
        $(obj).attr("class","layui-btn layui-btn-normal");
        return false;
    }

    formData.append("type","add");
    formData.append("menuId",menuId);
    formData.append("advertContent",advertContent);
    formData.append("redEnvelopeAmount",redEnvelopeAmount);


    $.ajax({
        type:"post",
        url:"/advert/addNewUserAdvert",
        data:formData,
        processData : false,
        contentType : false,
        dataType:"json" ,
        success :function (data) {

            if(data.code == 1 && data.code != undefined){
                alert("添加成功");
                layer.close(addIndex);
                findNewUserAdvert();
            }else if(data == 9999 && data != undefined){
                window.location.href = "/login_toLogin";
            }else if(data == 1111 && data != undefined){
                alert("无权操作");
                $(obj).attr("disabled",false);
                $(obj).attr("class","layui-btn layui-btn-normal");
                layer.close(addIndex);
                findNewUserAdvert();
            }else if(data.code == 2 && data.code != undefined){
                alert("添加失败");
                $(obj).attr("disabled",false);
                $(obj).attr("class","layui-btn layui-btn-normal");
                layer.close(addIndex);
                findNewUserAdvert();
            }else if(data.code == 3 && data.code != undefined){
                alert("系统异常,请联系管理员");
                layer.close(addIndex);
                findNewUserAdvert();
            }
        }
    });
}

//查看详情
function findDetails(l) {

    var ad = list[l];
    var content = JSON.parse(ad.advertContent);
    var html = '<table style="border-collapse: separate;border-spacing: 10px"><tr><td style="text-align: right;font-size: 18px;font-weight: 600">内容描述:</td><td>'+content.content+'</td></tr><tr style="height: 300px"><td style="text-align: right;font-size: 18px;font-weight: 600">内容配图:</td><td><div>';
    for(var p in content.photo){
        if(p == 2 || p == 5 || p == 8){
            html += '<div style="width: 150px;height: 150px;border: 1px solid darkgrey;display: inline-block;vertical-align: top;text-align: center;line-height: 150px;cursor: pointer"><img id="img3" src="'+content.photo[p]+'" style="width: 150px;height: 150px;"/></div><br/><br/>';
        }else {
            html += '<div  style="width: 150px;height: 150px;border: 1px solid darkgrey;display: inline-block;vertical-align: top;text-align: center;line-height: 150px;cursor: pointer;margin-right: 10px"><img id="img1" src="'+content.photo[p]+'" style="width: 150px;height: 150px;"></div>';
        }

    }

    html += '</div></td></tr></table>';

    layer.open({
        title: ['广告内容清单','color: #2299ee;border-bottom: 1px solid;']
        ,type: 1
        ,content: html
        ,area: ['40%', '80%']
        ,maxmin:true
    });

}

//打开修改页面
var updateIndex;
var photos;
function showUpdatePage(l) {
    var ad = list[l];
    var content = JSON.parse(ad.advertContent);
    var html = '<table style="border-collapse: separate;border-spacing: 10px"><tr><td style="text-align: right;font-size: 18px;font-weight: 600">内容描述:</td><td><textarea id="upAdvertContent" style="height: 50px;width: 472px">'+content.content+'</textarea></td></tr>'+
        '<tr><td style="text-align: right">福袋金额(单位:分)</td><td><input id="upRedEnvelopeAmount" value="'+ad.redEnvelopeAmount+'" style="height: 30px;width: 472px"/></td></tr>'+
        '<tr style="height: 300px"><td style="text-align: right;font-size: 18px;font-weight: 600">内容配图:</td><td><div>'+
        '<div id="upd1" onclick="upim1.click()" style="width: 150px;height: 150px;border: 1px solid darkgrey;display: inline-block;vertical-align: top;text-align: center;line-height: 150px;cursor: pointer"><input onchange="updatePreview(this,1)" id="upim1" type="file" style="display: none"/><label id="upt1">点击上传图片一</label><img id="upimg1" src="" style="width: 150px;height: 150px;display: none"/></div>'+
        '<div id="upd2" onclick="upim2.click()" style="width: 150px;height: 150px;border: 1px solid darkgrey;display: inline-block;vertical-align: top;margin-left: 10px;text-align: center;line-height: 150px;cursor: pointer"><input onchange="updatePreview(this,2)" id="upim2" type="file" style="display: none"/><label id="upt2">点击上传图片二</label><img id="upimg2" src="" style="width: 150px;height: 150px;display: none"/></div>'+
        '<div id="upd3" onclick="upim3.click()" style="width: 150px;height: 150px;border: 1px solid darkgrey;display: inline-block;vertical-align: top;margin-left: 10px;text-align: center;line-height: 150px;cursor: pointer"><input onchange="updatePreview(this,3)" id="upim3" type="file" style="display: none"/><label id="upt3">点击上传图片三</label><img id="upimg3" src="" style="width: 150px;height: 150px;display: none"/></div><br/><br/>'+
        '<div id="upd4" onclick="upim4.click()" style="width: 150px;height: 150px;border: 1px solid darkgrey;display: inline-block;vertical-align: top;text-align: center;line-height: 150px;cursor: pointer"><input onchange="updatePreview(this,4)" id="upim4" type="file" style="display: none"/><label id="upt4">点击上传图片四</label><img id="upimg4" src="" style="width: 150px;height: 150px;display: none"/></div>'+
        '<div id="upd5" onclick="upim5.click()" style="width: 150px;height: 150px;border: 1px solid darkgrey;display: inline-block;vertical-align: top;margin-left: 10px;text-align: center;line-height: 150px;cursor: pointer"><input onchange="updatePreview(this,5)" id="upim5" type="file" style="display: none"/><label id="upt5">点击上传图片五</label><img id="upimg5" src="" style="width: 150px;height: 150px;display: none"/></div>'+
        '<div id="upd6" onclick="upim6.click()" style="width: 150px;height: 150px;border: 1px solid darkgrey;display: inline-block;vertical-align: top;margin-left: 10px;text-align: center;line-height: 150px;cursor: pointer"><input onchange="updatePreview(this,6)" id="upim6" type="file" style="display: none"/><label id="upt6">点击上传图片六</label><img id="upimg6" src="" style="width: 150px;height: 150px;display: none"/></div><br/><br/>'+
        '<div id="upd7" onclick="upim7.click()" style="width: 150px;height: 150px;border: 1px solid darkgrey;display: inline-block;vertical-align: top;text-align: center;line-height: 150px;cursor: pointer"><input onchange="updatePreview(this,7)" id="upim7" type="file" style="display: none"/><label id="upt7">点击上传图片七</label><img id="upimg7" src="" style="width: 150px;height: 150px;display: none"/></div>'+
        '<div id="upd8" onclick="upim8.click()" style="width: 150px;height: 150px;border: 1px solid darkgrey;display: inline-block;vertical-align: top;margin-left: 10px;text-align: center;line-height: 150px;cursor: pointer"><input onchange="updatePreview(this,8)" id="upim8" type="file" style="display: none"/><label id="upt8">点击上传图片八</label><img id="upimg8" src="" style="width: 150px;height: 150px;display: none"/></div>'+
        '<div id="upd9" onclick="upim9.click()" style="width: 150px;height: 150px;border: 1px solid darkgrey;display: inline-block;vertical-align: top;margin-left: 10px;text-align: center;line-height: 150px;cursor: pointer"><input onchange="updatePreview(this,9)" id="upim9" type="file" style="display: none"/><label id="upt9">点击上传图片九</label><img id="upimg9" src="" style="width: 150px;height: 150px;display: none"/></div>'+
        '</div></td></tr></table>'+
        "<button onclick='updateNewUserAdvert(this,"+ad.id+")' class='layui-btn layui-btn-normal' style='float: right;margin-right: 10px;margin-top: 57px;margin-bottom: 10px'>提交</button>";

    updateIndex = layer.open({
        title: ['广告内容清单','color: #2299ee;border-bottom: 1px solid;']
        ,type: 1
        ,content: html
        ,area: ['40%', '80%']
        ,maxmin:true
    });
    photos = content.photo;
    // console.log(photos.join(","));
    // alert(photos.length);
    for(var p in photos){
        var num = parseInt(p)+1;
        console.log(content.photo[p]);
        $("#upt"+num).css("display","none");
        $("#upimg"+num).attr("src",content.photo[p]).css("display","block");
    }
}

//修改图片预览
function updatePreview(file, id) {
    if(photos != null && photos != undefined && id <= photos.length){
        photos[id-1] = null;
    }
    var prevDiv = document.getElementById('upd' + id);
    if(!file.files[0]){
        $("#upimg"+id).attr("src","");
        $("#upimg"+id).css("display","none");
        $(prevDiv).attr("line-height","30px");
        $("#upt"+id).css("display","block");
        return;
    }

    var fileType = file.files[0].type;
    if(fileType != "image/pjpeg" && fileType != "image/jpeg" && fileType != "image/x-png" && fileType != "image/png"){
        alert("图片类型错误");
        return false;
    }
    if (file.files && file.files[0]) {
        var reader = new FileReader();
        reader.onload = function (evt) {
            $(prevDiv).removeAttr("line-height");
            $("#upt"+id).css("display","none");
            $("#upimg"+id).attr("src",evt.target.result);
            $("#upimg"+id).css("display","block");
            // prevDiv.innerHTML = '<input onchange="preview(this,'+id+')" id="im'+id+'" type="file" style="display: none"/><img src="' + evt.target.result + '" style="width: 150px;height: 150px;"/>';
        }
        reader.readAsDataURL(file.files[0]);
    } else {
        prevDiv.innerHTML = '<input onchange="preview(this,'+id+')" id="im'+id+'" type="file" style="display: none"/><div class="img" style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale,src=\'' + file.value + '\'"></div>';
    }
}

//修改新用户福袋
function updateNewUserAdvert(obj,id) {
    $(obj).attr("disabled",true);
    $(obj).attr("class","layui-btn layui-btn-disabled");

    var menuId = $("#menuId").val();
    var formData = new FormData();

    var upAdvertContent = $("#upAdvertContent").val();
    if(upAdvertContent == "" || upAdvertContent == undefined){
        alert("福袋内容不能为空");
        $(obj).attr("disabled",false);
        $(obj).attr("class","layui-btn layui-btn-normal");
        return false;
    }
    var upRedEnvelopeAmount = $("#upRedEnvelopeAmount").val();
    if(upRedEnvelopeAmount == "" || upRedEnvelopeAmount == undefined){
        alert("福袋金额不能为空");
        $(obj).attr("disabled",false);
        $(obj).attr("class","layui-btn layui-btn-normal");
        return false;
    }
    if(isNaN(upRedEnvelopeAmount)){
        alert("福袋金额填写错误");
        $(obj).attr("disabled",false);
        $(obj).attr("class","layui-btn layui-btn-normal");
        return false;
    }
    var files = new Array();
    for(var i=1;i<=9;i++){
        var file = $("#upim"+i)[0].files[0];
        if(file != undefined){
            files.push(file);
            formData.append("files",file);
        }
    }
    console.log(files.length);
    if(photos != null && photos != undefined && photos.length <= 0){
        alert("请最少上传一张图片");
        $(obj).attr("disabled",false);
        $(obj).attr("class","layui-btn layui-btn-normal");
        return false;
    }

    formData.append("type","change");
    formData.append("menuId",menuId);
    formData.append("advertContent",upAdvertContent);
    formData.append("redEnvelopeAmount",upRedEnvelopeAmount);
    formData.append("photos",photos);
    formData.append("id",id);


    $.ajax({
        type:"post",
        url:"/advert/updateNewUserAdvert",
        data:formData,
        processData : false,
        contentType : false,
        dataType:"json" ,
        success :function (data) {

            if(data.code == 1 && data.code != undefined){
                alert("修改成功");
                layer.close(updateIndex);
                findNewUserAdvert();
            }else if(data == 9999 && data != undefined){
                window.location.href = "/login_toLogin";
            }else if(data == 1111 && data != undefined){
                alert("无权操作");
                $(obj).attr("disabled",false);
                $(obj).attr("class","layui-btn layui-btn-normal");
                layer.close(updateIndex);
                findNewUserAdvert();
            }else if(data.code == 2 && data.code != undefined){
                alert("修改失败");
                $(obj).attr("disabled",false);
                $(obj).attr("class","layui-btn layui-btn-normal");
                layer.close(updateIndex);
                findNewUserAdvert();
            }else if(data.code == 3 && data.code != undefined){
                alert("系统异常,请联系管理员");
                layer.close(updateIndex);
                findNewUserAdvert();
            }
        }
    });
}